<template>
    <div class="animation-container">
      <div class="sun"></div>
      <div v-for="(ball, index) in balls" :key="index" class="ball" :style="{ top: ball.top + 'px', left: ball.left + 'px', animationDelay: ball.delay + 's' }"></div>
    </div>
  </template>
  
  <script>
  export default {
    data() {
      return {
        balls: []
      };
    },
    mounted() {
      this.createBalls();
    },
    methods: {
      createBalls() {
        // 初始化小球的位置
        for (let i = 0; i < 8; i++) {
          this.balls.push({
            top: Math.floor(Math.random() * 300),
            left: Math.floor(Math.random() * 300),
            delay: Math.random() * 2 // 设置随机延迟，让小球分批次移动
          });
        }
      }
    }
  };
  </script>
  
  <style>
  .animation-container {
    position: relative;
    width: 400px;
    height: 400px;
  }
  
  .sun {
    width: 50px;
    height: 50px;
    background-color: yellow;
    border-radius: 50%;
    position: absolute;
    top: 175px;
    left: 175px;
  }
  
  .ball {
    width: 20px;
    height: 20px;
    background-color: blue;
    border-radius: 50%;
    position: absolute;
    animation: moveBall 2s ease-in-out infinite;
  }
  
  @keyframes moveBall {
    0% {
      transform: translate(0, 0);
      opacity: 1;
    }
    50% {
      transform: translate(calc(175px - 50%), calc(175px - 50%));
      opacity: 0;
    }
    100% {
      transform: translate(0, 0);
      opacity: 1;
    }
  }
  </style>
  